<?php
if(!defined('EC_K')) {
	exit('Access Denied.');
}

if ($_SERVER["REQUEST_METHOD"]=="GET" && $_GET['act'] == 'new')
{
	$name=$_GET['name'];
	$email=$_GET['email'];
	$pass=$_GET['pass'];
	$re_pass=$_GET['re_pass'];
//判断数据格式
	
    if(!$name) {
        exit("请填写您的用户名!");
    }
    if(StrLenW($name)>15 || StrLenW($name)<5) {
        exit("用户名长度应该大于5小于15个字符！");
    }
	if(!CheckUser($name)){
		exit("用户名格式不正确");
	}
	if(!CheckEmail($email)){
		exit("邮箱格式不正确");
	}
	 if(!$email) {
        exit("请填写邮箱地址!");
    }
    $sql = "select uid from ec_reguser where username='$name'";
	$query = $db->query($sql);
    if ($db->fetch_array($query)) {
        exit("用户名已存在，不能使用!");
    }
    $sql = "select uid from ec_reguser where email='$email'";
	$query = $db->query($sql);
    if ($db->fetch_array($query)) {
        exit("此电子邮件已存在，不能使用!");
    }
    // 密码
    if (StrLenW($pass)<6 || StrLenW($pass)>32) {
        exit("密码长度不能小于6位!");
    }
    if ($pass!=$re_pass) {
        exit("两次输入的密码不一致!");
    }

//加入数据库
	$dateline=time();
	$vcode=getRandchar();
	$t=$db->query("INSERT INTO ec_reguser (username,email,password,flag,dateline,vcode) VALUES ('$name','$email','".md5($pass)."',0,'$dateline','$vcode')");
	$regid=mysql_insert_id();
	if($t==1 && $regid) 
		{
			//$db->query("INSERT INTO et_friend (fid_jieshou,fid_fasong) VALUES ('1','$regid')");
			//$db->query("INSERT INTO et_friend (fid_jieshou,fid_fasong) VALUES ('$regid','1')");
			//dsetcookie('authcookie', authcode(md5(md5($pass2))."\t$mailadres\t$regid",'ENCODE'));
			$code=$name."_".$vcode;
			SendMail($code);
			$active=DeCode($code,'E','econtact');
			$active=$root."/ec.php?ac=verify&active=".$active;
			SendMail($active);
			exit("success");
		}
	else{
			exit("未知原因.");
		}
}

include($template->getfile('ec_register.htm'));
?>